// src/store/index.js

import { createStore } from 'vuex';

export default createStore({
  state: {
    isLoggedIn: false, // 是否已登录
    userName: ''       // 当前用户名
  },
  mutations: {
    // 设置登录状态
    setLoginState(state, payload) {
      state.isLoggedIn = true;
      state.userName = payload.username;
    },
    // 清除登录状态
    clearLoginState(state) {
      state.isLoggedIn = false;
      state.userName = '';
    }
  },
  actions: {
    // 登录操作
    login({ commit }, payload) {
      commit('setLoginState', payload);
    },
    // 登出操作
    logout({ commit }) {
      commit('clearLoginState');
    }
  }
});
